<template>
  <span>
    <template v-if="startTime != null">
      耗时:
      {{
        endTime == null ? (new Date().getTime() - startTime) / 1000 : (endTime - startTime) / 1000
      }}s
    </template>
  </span>
</template>
<script>
import { ref } from 'vue'
export default {
  expose: ['startCount', 'endCount', 'clear'],
  setup(props) {
    const startTime = ref(null)
    const endTime = ref(null)
    const startCount = () => {
      startTime.value = new Date().getTime()
      endTime.value = null
    }
    const endCount = () => {
      endTime.value = new Date().getTime()
    }
    const clear = () => {
      endTime.value = null
      startTime.value = null
    }
    return { startCount, endCount, startTime, endTime, clear }
  }
}
</script>
